package com.telit.dispose.entity.dispose;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Date;


/**
 * 元数据-字段
 * Create by Chencf 2022/08/05
 */
@Setter
@Getter
@TableName("plat_meta_field")
public class PlatMetaFieldEntity implements Serializable {

    private static final String PRIMARY_KEY_YES = "1";
    private static final String PRIMARY_KEY_NO = "0";

    private static final String NOT_NULL_YES = "1";
    private static final String NOT_NULL_NO = "0";

    private static final String GEOMETRY_TYPE_POINT = "point";
    private static final String GEOMETRY_TYPE_LINE = "line";
    private static final String GEOMETRY_TYPE_POLYGON = "polygon";

    //    //@MetaData(value = "编号")
    @ApiModelProperty(value = "主键ID")
    @TableId(value = "id", type = IdType.UUID)
    @Length(max = 32)
    private String id;

    @ApiModelProperty(value = "字段code  比如  name")
    @TableField("code")
    @NotBlank
    @Length(max = 32)
    private String code;

    @ApiModelProperty(value = "字段名称   比如 姓名")
    @TableField("name")
    @NotBlank
    @Length(max = 100)
    private String name;

    @ApiModelProperty(value = "字段类型")
    @TableField("type")
    @NotBlank
    @Length(max = 50)
    private String type;

    /**
     * 控件字段类型，point：点；line：线；polygon：面
     */
//    //@MetaData(value = "geometry类型")
    @TableField("geometry_type")
    @Length(max = 50)
    private String geometryType;

    //    //@MetaData(value = "长度")
    @TableField("length")
    private int length = 0;

    //    //@MetaData(value = "小数")
    @TableField("deci")
    private int deci = 0;

    //    //@MetaData(value = "排序")
    @TableField("sort")
    private int sort;

    //@MetaData(value = "单位")
    @TableField("unit")
    @Length(max = 20)
    private String unit;

    //@MetaData(value = "字典编码")
    @TableField("dict_code")
    @Length(max = 20)
    private String dictCode;

    //@MetaData(value = "默认值")
    @TableField("value")
    @Length(max = 100)
    private String value;

    //@MetaData(value = "验证器")
    @TableField("validator")
    @Length(max = 100)
    private String validator;

    //@MetaData(value = "是否创建")
    @TableField("is_create")
    @NotBlank
    @Length(max = 1)
    private String isCreate = "0";

    @ApiModelProperty(value = "所属表id")
    @TableField("table_id")
    @NotBlank
    @Length(max = 32)
    private String tableId;

    @ApiModelProperty(value = "描述")
    @TableField("description")
    @Length(max = 500)
    private String description;

    /**
     * 标识字段是否主键，0：不是；1：是
     */
    @ApiModelProperty(value = "主键")
    @TableField("primary_key")
    @Length(max = 1)
    private String primaryKey = PRIMARY_KEY_NO;

    /**
     * 标识字段不为空，0：为空；1：不为空
     */
    //@MetaData(value = "不为空")
    @TableField("not_null")
    @Length(max = 1)
    private String notNull = NOT_NULL_NO;

    /**
     * 表单显示控制（0：不显示；1：显示）
     */
    //@MetaData(value = "表单显示控制")
    //@TableField("display_form")
//    @Length(max = 1)
//    private String displayForm;

    /**
     * 列表显示控制（0：不显示；1：显示）
     */
    //@MetaData(value = "列表显示控制")
    // @TableField("display_list")
//    @Length(max = 1)
//    private String displayList;

    @ApiModelProperty(value = "删除标识 0 否 1 是")
    @TableField("delete_flag")
    @Length(max = 1)
    private String deleteFlag = PRIMARY_KEY_NO;

    //@MetaData(value = "创建人编号")
    @TableField("create_by")
    @Length(max = 32)
    private String createBy;

    //@MetaData(value = "创建人姓名")
    @TableField("create_name")
    @Length(max = 100)
    private String createName;

    //@MetaData(value = "创建日期")
    @TableField("create_date")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date createDate;

    //@MetaData(value = "修改人编号")
    @TableField("update_by")
    @Length(max = 32)
    private String updateBy;

    //@MetaData(value = "修改人姓名")
    @TableField("update_name")
    @Length(max = 100)
    private String updateName;

    //@MetaData(value = "修改日期")
    @TableField("update_date")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date updateDate;

    //@MetaData(value = "租户")
    @TableField("tentment_id")
    @Length(max = 100)
    private String tentmentId;

    //@MetaData(value = "表编码")
    @TableField(exist = false)
    private String tableCode;


    /**
     * 设置编码
     *
     * @param code 编码
     */
    public void setCode(String code) {
        if (StringUtils.isNotBlank(code)) {
            this.code = code.toLowerCase();
        } else {
            this.code = null;
        }
    }

    /**
     * 设置类型
     *
     * @param type 类型
     */
    public void setType(String type) {
        if (StringUtils.isNotBlank(type)) {
            this.type = type.toLowerCase();
        } else {
            this.type = null;
        }
    }

}
